package com.example.springboot01.mapper;


import com.example.springboot01.entity.UserInfo;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Repository;

import java.util.List;

@Mapper
@Repository
public interface UserInfoMapper {
    @Select("select * from user_info where user_code=#{userCode} " +
            " and user_pwd=#{userPwd}")
    UserInfo checkLogin(@Param("userCode") String user_code,
                        @Param("userPwd") String user_pwd);

    @Select("SELECT u.*, p.pro_name " +
            "    FROM user_info u INNER JOIN pro_info p " +
            "    ON p.pro_id = u.user_pro_id " +
            "    where ${fieldName} like '%${fieldValue}%'")
    List<UserInfo> qryUserList(@Param("fieldName") String field_name,
                               @Param("fieldValue") String field_value);
    //真正工作基本上不允许真的删除这条数据，而应该通过udpate status=0来区分开。
    @Delete("delete from user_info where user_code=#{user_code}")
    int deleteUser(@Param("user_code") String user_code);

    @Update("")
    int updateUser();

    @Insert("insert into user_info(user_code, user_name, user_pwd, telephone, user_pro_id) " +
            "    values(#{user_code}, #{user_name}, #{user_pwd}, " +
            "    #{telephone}, #{user_pro_id})")
    int insertUser(UserInfo userInfo);
    //#{}里面的名字是来自UserInfo类里面的私有变量
    //user_info()里面的名字是来自数据库里面的列名

    @Select("select * from user_info where user_code=#{user_code}")
    UserInfo getAUserInfo(@Param("user_code") String user_code);

    @Update("update user_info set user_name=#{user_name}, telephone=#{telephone}," +
            "   user_pro_id=#{user_pro_id}" +
            "    where user_code=#{user_code}")
    int editUser(UserInfo userInfo);
    @Select("SELECT u.*, p.pro_name " +
            "    FROM user_info u INNER JOIN pro_info p " +
            "    ON p.pro_id = u.user_pro_id " +
            "    where ${fieldName} like '%${fieldValue}%' " +
            "    limit ${currentPos}, ${pageSize}")
    List<UserInfo> qryUserPageList(@Param("fieldName") String field_name,
                                   @Param("fieldValue") String field_value,
                                   @Param("currentPos") int current_pos,
                                   @Param("pageSize") int page_size);
}
